package com.live.dengdengtv.fragment;

import android.support.v4.app.Fragment;

import com.live.dengdengtv.bean.SimpleInfoData;
import com.live.dengdengtv.net.callback.ProgressDialogCallBack;
import com.live.dengdengtv.net.callback.RequestNetCallback;
import com.live.dengdengtv.utils.Notice;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import java.util.Map;

import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by wyf on 2016/7/27.
 */
public class BaseFragment extends Fragment implements RequestNetCallback{

    protected void requestData(String url, Map<String, String> params, int id){
        requestNetData(url, params, id, true);
    }
    protected void requestNetData(String url, Map<String, String> params,int id, boolean isShowProgress){

        Callback callback;
        if(isShowProgress){
            callback = new ProgressDialogCallBack(getActivity(),this);
        }else {
            callback = new ProgressDialogCallBack(null,this);
        }
        OkHttpUtils.post().id(id).tag(this.getClass().getName()).url(url).params(params).build().execute(callback);
    }


    @Override
    public void onBefore(Request request, int id) {

    }

    @Override
    public void onAfter(int id) {

    }

    @Override
    public void inProgress(float progress, long total, int id) {

    }

    @Override
    public void onError(Call call, Exception e, int id) {
        Notice.alert(getActivity(), e.getMessage());
    }

    @Override
    public boolean onResponse(SimpleInfoData response, int id) {
        return false;
    }
}
